package com.graduation.common.interceptors;

import com.graduation.common.exceptions.UnAuthorizationException;
import com.graduation.common.utils.UserContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;


public class LoginUserAuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Long userId = UserContext.getUser();
        if (userId == null) {
            throw new UnAuthorizationException("未登录");
        }
        return true;
    }
}
